package com.rbac.web.model.res;

import com.rbac.web.model.Permission;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author gengaoliu
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "菜单列表返回参数")
public class PermissionGetListRes {

  private Integer id;
  private String code;
  private String name;
  private String displayName;
  private String action;
  private String type;
  private Integer pId;
  private String icon;
  private String value;
  private Integer menuId;
  private Integer sort;
  private String path;
  private String remark;
  private LocalDateTime createTime;

  public static PermissionGetListRes from(Permission permission) {
    return PermissionGetListRes.builder()
        .id(permission.getId())
        .code(permission.getCode())
        .name(permission.getName())
        .displayName(permission.getDisplayName())
        .action(permission.getAction().getValue())
        .type(permission.getType().getValue())
        .pId(permission.getPId())
        .icon(permission.getIcon())
        .value(permission.getValue())
        .menuId(permission.getMenuId())
        .sort(permission.getSort())
        .path(permission.getPath())
        .remark(permission.getRemark())
        .createTime(permission.getCreatedTime())
        .build();
  }
}
